<?php

class Optin extends Model_Abstract
{
	public function addOptinUser($uid)
	{
		try
		{
			$sql = " SELECT * FROM eversave_optin WHERE uid=? ";
			$result = $this->_connection->query($sql, array($uid));
			if(empty($result)){
				$sql = "INSERT INTO eversave_optin SET uid=?";
				return $this->_connection->execute($sql, array($uid));				
			}
		}
		catch (Exception $e)
		{
			QLog::log(__CLASS__.' '.__METHOD__.' --- '.$e->getMessage(), QLog::ERR);
			throw new Model_Exception($e->getMessage(), $e->getCode());
		}
	}
	
	public function addShoppingJobsOptinUser($uid)
	{
		try
		{
			$sql = " SELECT * FROM shoppingjobs_optin WHERE uid=? ";
			$result = $this->_connection->query($sql, array($uid));
			if(empty($result)){
				$sql = "INSERT INTO shoppingjobs_optin SET uid=?";
				return $this->_connection->execute($sql, array($uid));				
			}
		}
		catch (Exception $e)
		{
			QLog::log(__CLASS__.' '.__METHOD__.' --- '.$e->getMessage(), QLog::ERR);
			throw new Model_Exception($e->getMessage(), $e->getCode());
		}
	}
	
	public function addInPaysOptinUser($uid)
	{
		try
		{
			$sql = " SELECT * FROM inpays_optin WHERE uid=? ";
			$result = $this->_connection->query($sql, array($uid));
			if(empty($result)){
				$sql = "INSERT INTO inpays_optin SET uid=?";
				return $this->_connection->execute($sql, array($uid));				
			}
		}
		catch (Exception $e)
		{
			QLog::log(__CLASS__.' '.__METHOD__.' --- '.$e->getMessage(), QLog::ERR);
			throw new Model_Exception($e->getMessage(), $e->getCode());
		}
	}
	
	public function addGreateAmericanUser($uid)
	{
		try
		{
			$sql = " SELECT * FROM greateamerican_optin WHERE uid=? ";
			$result = $this->_connection->query($sql, array($uid));
			if(empty($result)){
				$sql = "INSERT INTO greateamerican_optin SET uid=?";
				return $this->_connection->execute($sql, array($uid));				
			}
		}
		catch (Exception $e)
		{
			QLog::log(__CLASS__.' '.__METHOD__.' --- '.$e->getMessage(), QLog::ERR);
			throw new Model_Exception($e->getMessage(), $e->getCode());
		}
	}
}
?>